@echo off
echo 设置文件权限脚本
echo 需要以管理员权限运行
echo.

REM 检查管理员权限
net session >nul 2>&1
if %errorLevel% neq 0 (
    echo 错误：请以管理员权限运行此脚本！
    pause
    exit /b 1
)

REM 设置项目文件夹权限
echo 设置项目文件夹权限...
icacls "%~dp0" /grant "IIS_IUSRS:(OI)(CI)F" /T
icacls "%~dp0" /grant "NETWORK SERVICE:(OI)(CI)F" /T
icacls "%~dp0" /grant "IUSR:(OI)(CI)F" /T

REM 创建必要的文件夹
if not exist "uploads" mkdir "uploads"
if not exist "data" mkdir "data"

REM 设置上传文件夹权限
echo 设置上传文件夹权限...
icacls "uploads" /grant "IIS_IUSRS:(OI)(CI)F"
icacls "uploads" /grant "NETWORK SERVICE:(OI)(CI)F"
icacls "uploads" /grant "IUSR:(OI)(CI)F"

REM 设置数据文件夹权限
echo 设置数据文件夹权限...
icacls "data" /grant "IIS_IUSRS:(OI)(CI)F"
icacls "data" /grant "NETWORK SERVICE:(OI)(CI)F"
icacls "data" /grant "IUSR:(OI)(CI)F"

echo.
echo 权限设置完成！
echo.
echo 请确保以下组件已安装：
echo 1. Node.js
echo 2. IIS URL Rewrite Module
echo 3. IIS Node.js 处理程序 (iisnode)
echo.
pause 